﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HotelG11.Models;
using PagedList;

namespace HotelG11.Controllers
{
    [Authorize(Roles = "LOAINV2")]
    public class NVQuanTriController : Controller
    {

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult QuanLyTaiKhoan()
        {
            return View();
        }

        public ActionResult LayDanhSachTaiKhoan(int isCT,int? page)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            var TKCty = from tkct in G11.G11_TaiKhoan select tkct;
            if (isCT == 1)
            {
                TKCty = TKCty.Where(tkct => tkct.tenTaiKhoan.ToUpper().Contains("CT_"));
            }
            else
            {
                TKCty = TKCty.Where(tkct => tkct.tenTaiKhoan.ToUpper().Contains("NV_"));
            }
            TKCty = TKCty.OrderBy(tkct => tkct.tenTaiKhoan);
            int pageNumber = (page ?? 1);

            return PartialView(TKCty.ToPagedList(pageNumber, 10));
        }

        [HttpGet]
        public ActionResult ThemTaiKhoan(int isCT, string tenTK, string maTK, string email, int? page)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_ThemTaiKhoanKhachSan(tenTK, maTK ,email);
            var TKCty = from tkct in G11.G11_TaiKhoan select tkct;
            if (isCT == 1)
            {
                TKCty = TKCty.Where(tkct => tkct.tenTaiKhoan.ToUpper().Contains("CT_"));
            }
            else
            {
                TKCty = TKCty.Where(tkct => tkct.tenTaiKhoan.ToUpper().Contains("NV_"));
            }
            TKCty = TKCty.OrderBy(tkct => tkct.tenTaiKhoan);
            int pageNumber = (page ?? 1);

            return PartialView("LayDanhSachTaiKhoan", TKCty.ToPagedList(pageNumber, 10));
        }

        [HttpGet]
        public ActionResult CapNhatTaiKhoan(int isCT, string tenTK, string maTK, string email, int? page)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_SuaTaiKhoanKhachSan(tenTK, maTK, email);
            var TKCty = from tkct in G11.G11_TaiKhoan select tkct;
            if (isCT == 1)
            {
                TKCty = TKCty.Where(tkct => tkct.tenTaiKhoan.ToUpper().Contains("CT_"));
            }
            else
            {
                TKCty = TKCty.Where(tkct => tkct.tenTaiKhoan.ToUpper().Contains("NV_"));
            }
            TKCty = TKCty.OrderBy(tkct => tkct.tenTaiKhoan);
            int pageNumber = (page ?? 1);

            return PartialView("LayDanhSachTaiKhoan", TKCty.ToPagedList(pageNumber, 10));
        }

        [HttpGet]
        public ActionResult XoaTaiKhoan(int isCT, string tenTK, int? page)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            G11.sp_XoaTaiKhoanKhachSan(tenTK);
            var TKCty = from tkct in G11.G11_TaiKhoan select tkct;
            if (isCT == 1)
            {
                TKCty = TKCty.Where(tkct => tkct.tenTaiKhoan.ToUpper().Contains("CT_"));
            }
            else
            {
                TKCty = TKCty.Where(tkct => tkct.tenTaiKhoan.ToUpper().Contains("NV_"));
            }
            TKCty = TKCty.OrderBy(tkct => tkct.tenTaiKhoan);
            int pageNumber = (page ?? 1);

            return PartialView("LayDanhSachTaiKhoan", TKCty.ToPagedList(pageNumber, 10));
        }
        [HttpGet]
        public ActionResult KiemTraIDTaiKhoan(string tenTK)
        {
            G11KhachSanEntities G11 = new G11KhachSanEntities();
            string ma = G11.sp_KiemTraIDTaiKhoan(tenTK).FirstOrDefault();
            return Content(ma);
        }
    }
}
